package edu.drexel.cs575.taskManager.gui;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Helper {
	
	public static boolean isLoggedIn(HttpServletRequest request){
		List<Cookie> cookies = Arrays.asList(request.getCookies());
		
		Iterator<Cookie> iterator = cookies.iterator();
		while(iterator.hasNext()){
			Cookie next = iterator.next();
			String name = next.getName();
			if(name.equals("userName")){
				return true;
			}
		}
		return false;
	}
	
	public static String getUserName(HttpServletRequest request){
		List<Cookie> cookies = Arrays.asList(request.getCookies());
		String userName = "";
		
		Iterator<Cookie> iterator = cookies.iterator();
		while(iterator.hasNext()){
			Cookie next = iterator.next();
			String name = next.getName();
			if(name.equals("userName")){
				userName = next.getValue();
			}
		}
		return userName;
	}

}
